package book_management;

import book_management.book.BookList;
import book_management.user.AdminUser;
import book_management.user.NormalUser;
import book_management.user.User;

import java.util.NoSuchElementException;
import java.util.Scanner;

/**
 * 程序的入口
 * @author yuisama
 * @date 2022/05/08 17:58
 **/
public class Main {
    public static void main(String[] args) {
        // 1.此时图书馆只有一个书架
        BookList bookList = new BookList();
        // 2.用户登录操作
        User user = login();
        // 3.开始进行选择
        while (true) {
            int choice = user.menu();
            if (choice == -1) {
                System.out.println("Byebye~~");
                break;
            }
            user.doOperation(bookList,choice);
        }
    }

    private static User login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的用户名:");
        String str = scanner.nextLine();
        System.out.println("请输入您登录的角色,1表示普通用户,0表示管理员");
        int choice = scanner.nextInt();
        if (choice == 1) {
            return new NormalUser(str);
        }else if (choice == 0){
            return new AdminUser(str);
        }
        throw new NoSuchElementException("键入有误，没有这个选项");
    }

}